/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TratamientoMedicamentosoPresentacion.java
 *
 * Created on 31-ago-2010, 11:35:04
 */

package presentacion.tratamiento_medicamentoso;

import hibernate.objeto.Evolucion;
import hibernate.objeto.Farmacologico;
import hibernate.objeto.NoFarmacologico;
import hibernate.objeto.TratamientoMedicamentoso;
import java.awt.Component;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.RowFilter;
import javax.swing.table.TableRowSorter;
import logica.CapaLogica;
import logica.FarmacologicoLogica;
import logica.NoFarmacologicoLogica;
import logica.TratamientoMedicamentosoLogica;
import presentacion.CapaPresentacion;
import presentacion.GestionPacientePresentacion;
import presentacion.utilidad.PopUpMenu;
import presentacion.comun.ComunFarmacologicoPresentacion;
import presentacion.comun.ComunNoFarmacologicoPresentacion;
import presentacion.utilidad.maquetado.Fuente;
import presentacion.utilidad.maquetado.Icono;
import presentacion.utilidad.BarMenu;
import presentacion.utilidad.MensajePresentacion;
import presentacion.utilidad.tabla.MiModeloTabla;

/**
 *
 * @author Administrador
 */
public class TratamientoMedicamentosoPresentacion extends javax.swing.JDialog {

    /** Creates new form TratamientoMedicamentosoPresentacion */
    public TratamientoMedicamentosoPresentacion(java.awt.Frame parent,
            boolean modal, Evolucion unaEvolucion) {
        super(parent, modal);

        evolucion = unaEvolucion;
        tratamientoMedicamentoso = TratamientoMedicamentosoLogica.
                getTratamientoMedicamentosoPorIdEvolucion(
                evolucion.getIdEvolucion());
                
        initComponents();
        this.setSize(CapaPresentacion.getTamañoMaximoJDialog());
        setLocationRelativeTo(null);
        personalizarGUI();
        setearEventosQueCapturanTeclaEnterYEscape();
    }

    /**
     * Setea datos de la ventana
     * 
     */
    private void personalizarGUI() {
        //Crea la barra de menu
        this.setJMenuBar(BarMenu.createMenuBarTratamientoMedicamentoso(this));

        if (CapaPresentacion.modoCarga) {
            ;
        } else if (CapaPresentacion.modoModificacion) {
            ;
        } else if (CapaPresentacion.modoVisualizacion) {
            modoVisualizacion();
        }

        exhibirDatosEnPantalla();
    }

    /**
     * Setea la ventana en modo visualización.
     *
     */
    private void modoVisualizacion() {
        botonAgregarPanelFarmacologico.setVisible(false);
        botonAgregarPanelNoFarmacologico.setVisible(false);
        botonCancelar.requestFocus();
        CapaPresentacion.personalizarBotonesEnVisualizacion(
                    textoDescriptivoVentana, botonAceptar, botonCancelar);
    }

    /**
     * Carga los datos del tratamiento medicamentosos del paciente en pantalla.
     *
     */
    private void exhibirDatosEnPantalla() {
        CapaPresentacion.setearLabelEstado(evolucion, textoEstadoEntidad);
        
        vectorFarmacologicoActivo = FarmacologicoLogica.
                getVectorFarmacologicoActivoPorIdPaciente(
                GestionPacientePresentacion.getPaciente().getIdPaciente());
        MiModeloTabla.cargarTablaFarmacologico(
                vectorFarmacologicoActivo, tablaFarmacologicoActivo);
        //Esconde la columna que contiene la fecha y el estado
        tablaFarmacologicoActivo.removeColumn(
                tablaFarmacologicoActivo.getColumnModel().getColumn(0));
        tablaFarmacologicoActivo.removeColumn(
                tablaFarmacologicoActivo.getColumnModel().getColumn(1));
        
        //Si se trata de visualizacion
        if (tratamientoMedicamentoso != null) {
            //Farmacologico
            vectorFarmacologicoTratamientoMedicamentoso = FarmacologicoLogica.
                    getVectorFarmacologicoPorIdTratamientoMedicamentoso(
                    tratamientoMedicamentoso.getIdTratamientoMedicamentoso());
            MiModeloTabla.cargarTablaFarmacologico(
                    vectorFarmacologicoTratamientoMedicamentoso, tablaFarmacologico);

            //No Farmacologico
            vectorNoFarmacologicoTratamientoMedicamentoso = NoFarmacologicoLogica.
                    getVectorNoFarmacologicoPorIdTratamientoMedicamentoso(
                    tratamientoMedicamentoso.getIdTratamientoMedicamentoso());

            MiModeloTabla.cargarTablaNoFarmacologico(
                    vectorNoFarmacologicoTratamientoMedicamentoso, tablaNoFarmacologico);
        } else {
            //Inicializa las tablas vacias
            MiModeloTabla.cargarTablaFarmacologico(
                        null, tablaFarmacologico);
            MiModeloTabla.cargarTablaNoFarmacologico(
                        null, tablaNoFarmacologico);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        textoDescriptivoVentana = new javax.swing.JLabel();
        solapasTratamientoMedicamentoso = new javax.swing.JTabbedPane();
        panelFarmacologico = new javax.swing.JPanel();
        textoPanelFarmacologico = new javax.swing.JLabel();
        botonAgregarPanelFarmacologico = new javax.swing.JButton();
        textoDescriptivoFarmacologico = new javax.swing.JLabel();
        textoFiltrarFarmacologico = new javax.swing.JLabel();
        filtrarFarmacologico = new javax.swing.JTextField();
        tablaFarmacologicoScrollPanel = new javax.swing.JScrollPane();
        tablaFarmacologico = new javax.swing.JTable(new MiModeloTabla());
        panelFarmacologicoInternoScrollPanel = new javax.swing.JScrollPane();
        panelFarmacologicoInterno = new javax.swing.JPanel();
        textoFarmacologicoActivo = new javax.swing.JLabel();
        textoFiltrarFarmacologicoActivo = new javax.swing.JLabel();
        filtrarFarmacologicoActivo = new javax.swing.JTextField();
        tablaFarmacologicoActivoScrollPanel = new javax.swing.JScrollPane();
        tablaFarmacologicoActivo = new javax.swing.JTable(new MiModeloTabla());
        panelNoFarmacologico = new javax.swing.JPanel();
        textoPanelNoFarmacologico = new javax.swing.JLabel();
        botonAgregarPanelNoFarmacologico = new javax.swing.JButton();
        textoDescriptivoNoFarmacologico = new javax.swing.JLabel();
        textoFiltrarNoFarmacologico = new javax.swing.JLabel();
        filtrarNoFarmacologico = new javax.swing.JTextField();
        tablaNoFarmacologicoScrollPanel = new javax.swing.JScrollPane();
        tablaNoFarmacologico = new javax.swing.JTable(new MiModeloTabla());
        panelNoFarmacologicoInternoScrollPanel = new javax.swing.JScrollPane();
        panelNoFarmacologicoInterno = new javax.swing.JPanel();
        botonAceptar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        textoEstadoEntidad = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Tratamiento Medicamentoso");
        setMinimumSize(new java.awt.Dimension(1040, 731));

        textoDescriptivoVentana.setFont(Fuente.FUENTE_TITULO_2);
        textoDescriptivoVentana.setForeground(Fuente.COLOR_NORMAL);
        textoDescriptivoVentana.setText("Ingrese los datos del tratamiento medicamentoso");
        textoDescriptivoVentana.setPreferredSize(new java.awt.Dimension(836, 20));

        solapasTratamientoMedicamentoso.setForeground(Fuente.COLOR_NORMAL);
        solapasTratamientoMedicamentoso.setPreferredSize(new java.awt.Dimension(1004, 633));

        textoPanelFarmacologico.setFont(Fuente.FUENTE_TITULO_3);
        textoPanelFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoPanelFarmacologico.setText("Haga click para agregar tratamientos farmacológicos");
        textoPanelFarmacologico.setPreferredSize(new java.awt.Dimension(500, 23));

        botonAgregarPanelFarmacologico.setFont(Fuente.FUENTE_BOTON_INTERNO);
        botonAgregarPanelFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        botonAgregarPanelFarmacologico.setIcon(Icono.ICONO_16_AGREGAR);
        botonAgregarPanelFarmacologico.setMnemonic('t');
        botonAgregarPanelFarmacologico.setText("Agregar tratamiento");
        botonAgregarPanelFarmacologico.setToolTipText("Agrega los datos para completar un tratamiento farmacológico");
        botonAgregarPanelFarmacologico.setPreferredSize(new java.awt.Dimension(175, 23));
        botonAgregarPanelFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarPanelFarmacologicoActionPerformed(evt);
            }
        });

        textoDescriptivoFarmacologico.setFont(Fuente.FUENTE_TITULO_3);
        textoDescriptivoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoDescriptivoFarmacologico.setText("Lista de tratamientos farmacológicos que posee el paciente");
        textoDescriptivoFarmacologico.setPreferredSize(new java.awt.Dimension(500, 20));

        textoFiltrarFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoFiltrarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoFiltrarFarmacologico.setText("Filtrar");
        textoFiltrarFarmacologico.setPreferredSize(new java.awt.Dimension(28, 20));

        filtrarFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        filtrarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        filtrarFarmacologico.setToolTipText("Filtra los datos encontrados por algún criterio");
        filtrarFarmacologico.setMinimumSize(new java.awt.Dimension(0, 0));
        filtrarFarmacologico.setPreferredSize(new java.awt.Dimension(200, 20));
        filtrarFarmacologico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filtrarFarmacologicoKeyReleased(evt);
            }
        });

        tablaFarmacologicoScrollPanel.setMinimumSize(new java.awt.Dimension(0, 0));
        tablaFarmacologicoScrollPanel.setPreferredSize(new java.awt.Dimension(979, 132));

        tablaFarmacologico.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaFarmacologicoMouseClicked(evt);
            }
        });
        tablaFarmacologicoScrollPanel.setViewportView(tablaFarmacologico);
        MiModeloTabla.inicializarTabla(tablaFarmacologico);

        panelFarmacologicoInternoScrollPanel.setBorder(null);
        panelFarmacologicoInternoScrollPanel.setPreferredSize(new java.awt.Dimension(485, 380));

        panelFarmacologicoInterno.setLayout(new javax.swing.BoxLayout(panelFarmacologicoInterno, javax.swing.BoxLayout.Y_AXIS));
        panelFarmacologicoInternoScrollPanel.setViewportView(panelFarmacologicoInterno);

        textoFarmacologicoActivo.setFont(Fuente.FUENTE_TITULO_3);
        textoFarmacologicoActivo.setForeground(Fuente.COLOR_NORMAL);
        textoFarmacologicoActivo.setText("Medicamentos activos del paciente");
        textoFarmacologicoActivo.setPreferredSize(new java.awt.Dimension(200, 20));

        textoFiltrarFarmacologicoActivo.setFont(Fuente.FUENTE_LABEL);
        textoFiltrarFarmacologicoActivo.setForeground(Fuente.COLOR_NORMAL);
        textoFiltrarFarmacologicoActivo.setText("Filtrar");
        textoFiltrarFarmacologicoActivo.setPreferredSize(new java.awt.Dimension(28, 20));

        filtrarFarmacologicoActivo.setFont(Fuente.FUENTE_TEXTFIELD);
        filtrarFarmacologicoActivo.setForeground(Fuente.COLOR_NORMAL);
        filtrarFarmacologicoActivo.setToolTipText("Filtra los datos encontrados por algún criterio");
        filtrarFarmacologicoActivo.setMinimumSize(new java.awt.Dimension(0, 0));
        filtrarFarmacologicoActivo.setPreferredSize(new java.awt.Dimension(200, 20));
        filtrarFarmacologicoActivo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filtrarFarmacologicoActivoKeyReleased(evt);
            }
        });

        tablaFarmacologicoActivoScrollPanel.setMinimumSize(new java.awt.Dimension(0, 0));
        tablaFarmacologicoActivoScrollPanel.setPreferredSize(new java.awt.Dimension(484, 354));

        tablaFarmacologicoActivo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaFarmacologicoActivoMouseClicked(evt);
            }
        });
        tablaFarmacologicoActivoScrollPanel.setViewportView(tablaFarmacologicoActivo);
        MiModeloTabla.inicializarTabla(tablaFarmacologicoActivo);

        javax.swing.GroupLayout panelFarmacologicoLayout = new javax.swing.GroupLayout(panelFarmacologico);
        panelFarmacologico.setLayout(panelFarmacologicoLayout);
        panelFarmacologicoLayout.setHorizontalGroup(
            panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFarmacologicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tablaFarmacologicoScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFarmacologicoLayout.createSequentialGroup()
                        .addComponent(textoPanelFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 304, Short.MAX_VALUE)
                        .addComponent(botonAgregarPanelFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFarmacologicoLayout.createSequentialGroup()
                        .addComponent(textoDescriptivoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 247, Short.MAX_VALUE)
                        .addComponent(textoFiltrarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtrarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFarmacologicoLayout.createSequentialGroup()
                        .addComponent(panelFarmacologicoInternoScrollPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelFarmacologicoLayout.createSequentialGroup()
                                .addComponent(textoFarmacologicoActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                                .addComponent(textoFiltrarFarmacologicoActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(filtrarFarmacologicoActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(tablaFarmacologicoActivoScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE))))
                .addContainerGap())
        );
        panelFarmacologicoLayout.setVerticalGroup(
            panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFarmacologicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAgregarPanelFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoPanelFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filtrarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoFiltrarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoDescriptivoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablaFarmacologicoScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFarmacologicoLayout.createSequentialGroup()
                        .addGroup(panelFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(filtrarFarmacologicoActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textoFiltrarFarmacologicoActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textoFarmacologicoActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tablaFarmacologicoActivoScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(panelFarmacologicoInternoScrollPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        solapasTratamientoMedicamentoso.addTab("Farmacológico", panelFarmacologico);

        textoPanelNoFarmacologico.setFont(Fuente.FUENTE_TITULO_3);
        textoPanelNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoPanelNoFarmacologico.setText("Haga click para agregar tratamientos no farmacológicos");
        textoPanelNoFarmacologico.setPreferredSize(new java.awt.Dimension(500, 23));

        botonAgregarPanelNoFarmacologico.setFont(Fuente.FUENTE_BOTON_INTERNO);
        botonAgregarPanelNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        botonAgregarPanelNoFarmacologico.setIcon(Icono.ICONO_16_AGREGAR);
        botonAgregarPanelNoFarmacologico.setMnemonic('r');
        botonAgregarPanelNoFarmacologico.setText("Agregar tratamiento");
        botonAgregarPanelNoFarmacologico.setToolTipText("Agrega los datos para completar un tratamiento no farmacológico");
        botonAgregarPanelNoFarmacologico.setPreferredSize(new java.awt.Dimension(175, 23));
        botonAgregarPanelNoFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarPanelNoFarmacologicoActionPerformed(evt);
            }
        });

        textoDescriptivoNoFarmacologico.setFont(Fuente.FUENTE_TITULO_3);
        textoDescriptivoNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoDescriptivoNoFarmacologico.setText("Lista de tratamientos no farmacológicos que posee el paciente");
        textoDescriptivoNoFarmacologico.setPreferredSize(new java.awt.Dimension(500, 20));

        textoFiltrarNoFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoFiltrarNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoFiltrarNoFarmacologico.setText("Filtrar");
        textoFiltrarNoFarmacologico.setPreferredSize(new java.awt.Dimension(28, 20));

        filtrarNoFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        filtrarNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        filtrarNoFarmacologico.setToolTipText("Filtra los datos encontrados por algún criterio");
        filtrarNoFarmacologico.setMinimumSize(new java.awt.Dimension(0, 0));
        filtrarNoFarmacologico.setPreferredSize(new java.awt.Dimension(200, 20));
        filtrarNoFarmacologico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filtrarNoFarmacologicoKeyReleased(evt);
            }
        });

        tablaNoFarmacologicoScrollPanel.setMinimumSize(new java.awt.Dimension(0, 0));
        tablaNoFarmacologicoScrollPanel.setPreferredSize(new java.awt.Dimension(979, 132));
        MiModeloTabla.inicializarTabla(tablaNoFarmacologico);

        tablaNoFarmacologico.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaNoFarmacologicoMouseClicked(evt);
            }
        });
        tablaNoFarmacologicoScrollPanel.setViewportView(tablaNoFarmacologico);
        MiModeloTabla.inicializarTabla(tablaFarmacologico);

        panelNoFarmacologicoInternoScrollPanel.setBorder(null);
        panelNoFarmacologicoInternoScrollPanel.setPreferredSize(new java.awt.Dimension(485, 380));

        panelNoFarmacologicoInterno.setLayout(new javax.swing.BoxLayout(panelNoFarmacologicoInterno, javax.swing.BoxLayout.Y_AXIS));
        panelNoFarmacologicoInternoScrollPanel.setViewportView(panelNoFarmacologicoInterno);

        javax.swing.GroupLayout panelNoFarmacologicoLayout = new javax.swing.GroupLayout(panelNoFarmacologico);
        panelNoFarmacologico.setLayout(panelNoFarmacologicoLayout);
        panelNoFarmacologicoLayout.setHorizontalGroup(
            panelNoFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelNoFarmacologicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelNoFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tablaNoFarmacologicoScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelNoFarmacologicoLayout.createSequentialGroup()
                        .addComponent(textoPanelNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 304, Short.MAX_VALUE)
                        .addComponent(botonAgregarPanelNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelNoFarmacologicoLayout.createSequentialGroup()
                        .addComponent(textoDescriptivoNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 247, Short.MAX_VALUE)
                        .addComponent(textoFiltrarNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtrarNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(panelNoFarmacologicoInternoScrollPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panelNoFarmacologicoLayout.setVerticalGroup(
            panelNoFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelNoFarmacologicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelNoFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAgregarPanelNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoPanelNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelNoFarmacologicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filtrarNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoFiltrarNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoDescriptivoNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablaNoFarmacologicoScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelNoFarmacologicoInternoScrollPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        solapasTratamientoMedicamentoso.addTab("No Farmacológico", panelNoFarmacologico);

        botonAceptar.setFont(Fuente.FUENTE_BOTON_EXTERNO);
        botonAceptar.setForeground(Fuente.COLOR_NORMAL);
        botonAceptar.setIcon(Icono.ICONO_16_ACEPTAR);
        botonAceptar.setMnemonic('a');
        botonAceptar.setText("Aceptar");
        botonAceptar.setToolTipText("Agrega el tratamiento medicamentoso");
        botonAceptar.setPreferredSize(new java.awt.Dimension(110, 23));
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        botonCancelar.setFont(Fuente.FUENTE_BOTON_EXTERNO);
        botonCancelar.setForeground(Fuente.COLOR_NORMAL);
        botonCancelar.setIcon(Icono.ICONO_16_CANCELAR);
        botonCancelar.setMnemonic('c');
        botonCancelar.setText("Cancelar");
        botonCancelar.setToolTipText("Cancela la operación");
        botonCancelar.setPreferredSize(new java.awt.Dimension(110, 23));
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        textoEstadoEntidad.setFont(Fuente.FUENTE_TEXTFIELD);
        textoEstadoEntidad.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        textoEstadoEntidad.setPreferredSize(new java.awt.Dimension(150, 20));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(solapasTratamientoMedicamentoso, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(textoDescriptivoVentana, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(textoEstadoEntidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(textoEstadoEntidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoDescriptivoVentana, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(solapasTratamientoMedicamentoso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        agregarOModificarTratamientoMedicamentoso();
}//GEN-LAST:event_botonAceptarActionPerformed

    /**
     * Agrega/modifica los datos de los tratamientos farmacológicos del paciente.
     * 
     */
    private void agregarOModificarTratamientoMedicamentoso() {
        //Valida todos los datos ingresados
        if (validarCampos()) {
            //Carga toda la información de la pantalla
            recopilarInformacion();

            if (TratamientoMedicamentosoLogica.agregarTratamientoMedicamentoso(
                    datosFarmacologico, datosNoFarmacologico,
                    evolucion, tratamientoMedicamentoso)) {
                this.dispose();
            }

        } else {
            MensajePresentacion.errorDatosInvalidos();
        }
    }

    /**
     * Valida en conjunto todos los campos. Aquellos que son obligatorios y los
     * que no.
     *
     * @return true si el objeto está listo para cargarse, false en caso
     * contrario
     */
    private boolean validarCampos() {
        boolean farmacologico = validarDatosFarmacologico();
        boolean noFarmacologico = validarDatosNoFarmacologico();

        return (farmacologico && noFarmacologico);
    }

    /**
     * Valida los campos correspondiente al panel Farmacologico.
     *
     * @return true si los campos estan listos para cargarse, false en caso
     * contrario
     */
    public boolean validarDatosFarmacologico() {
        int retorno = 0;
        Component[] datosPanelFarmacologico =
                panelFarmacologicoInterno.getComponents();

        for (int i = 0; i < datosPanelFarmacologico.length; i++) {
            if (((DatosFarmacologico)
                    datosPanelFarmacologico[i]).validarCampos()) {
                retorno = retorno + 1;
            }
        }

        if (retorno == datosPanelFarmacologico.length){
            setearErrorTituloSolapas(true, 0);
            return true;
        } else {
            setearErrorTituloSolapas(false, 0);
            return false;
        }
    }

    /**
     * Valida los campos correspondiente al panel no farmacológico.
     *
     * @return true si los campos estan listos para cargarse, false en caso
     * contrario
     */
    public boolean validarDatosNoFarmacologico() {
        int retorno = 0;
        Component[] datosPanelNoFarmacologico =
                panelNoFarmacologicoInterno.getComponents();

        for (int i = 0; i < datosPanelNoFarmacologico.length; i++) {
            if (((DatosNoFarmacologico)
                    datosPanelNoFarmacologico[i]).validarCampos()) {
                retorno = retorno + 1;
            }
        }

        if (retorno == datosPanelNoFarmacologico.length){
            setearErrorTituloSolapas(true, 1);
            return true;
        } else {
            setearErrorTituloSolapas(false, 1);
            return false;
        }
    }

    /**
     * Setea el color del titulo de la pestaña seleccionada según la validez.
     *
     * @param valido true si debe setearse en rojo, false para setearlo en negro
     * @param indice el indice de la pestaña a setear
     *
     */
    public void setearErrorTituloSolapas(boolean valido, int indice) {
        if (!valido) {
            solapasTratamientoMedicamentoso.setForegroundAt(indice,
                    Fuente.COLOR_ERROR);
        } else {
            solapasTratamientoMedicamentoso.setForegroundAt(indice,
                    Fuente.COLOR_NORMAL);
        }
    }
    
    /**
     * Carga todos los datos ingresados en pantalla.
     *
     */
    private void recopilarInformacion() {
        recopilarInformacionFarmacologico();
        recopilarInformacionNoFarmacologico();
    }

    /**
     * Recopila toda la informacion ingresada en el panel de Farmacologico.
     *
     */
    private void recopilarInformacionFarmacologico() {
        Component[] componentesFarmacologico =
                panelFarmacologicoInterno.getComponents();

        datosFarmacologico =
                new Object[componentesFarmacologico.length][10];

        for (int i = 0; i < componentesFarmacologico.length; i++) {
            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_HORA] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getHoraFarmacologico();

            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_FECHA] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getFechaFarmacologico();

            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_NOMBRE_COMERCIAL_MEDICAMENTO] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getMedicamentoSeleccionado();

            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_DOSIS] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getDosisFarmacologico();

            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_INTERVALO] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getIntervaloFarmacologico();

            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_DURACION] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getDuracionFarmacologico();

            if (((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getEfectivoSiFarmacologico()) {
                datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_EFECTIVO] = "si";
            } else if (((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getEfectivoNoFarmacologico()) {
                datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_EFECTIVO] = "no";
            } else {
                datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_EFECTIVO] = "";
            }

            if (((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getEfectoAdversoSiFarmacologico()) {
                datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_EFECTO_ADVERSO] = "si";
            } else if (((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getEfectoAdversoNoFarmacologico()) {
                datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_EFECTO_ADVERSO] = "no";
            } else {
                datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_EFECTO_ADVERSO] = "";
            }

            datosFarmacologico[i][
                    CapaLogica.FARMACOLOGICO_COMENTARIOS] =
                    ((DatosFarmacologico)
                    componentesFarmacologico[i]).
                    getComentariosFarmacologico();

            datosFarmacologico[i][CapaLogica.FARMACOLOGICO_ESTADO] = "Activo";
        }
    }

    /**
     * Recopila toda la informacion ingresada en el panel de No Farmacologico.
     *
     */
    private void recopilarInformacionNoFarmacologico() {
        Component[] componentesNoFarmacologico =
                panelNoFarmacologicoInterno.getComponents();

        datosNoFarmacologico =
                new Object[componentesNoFarmacologico.length][4];

        for (int i = 0; i < componentesNoFarmacologico.length; i++) {
            //Hora
            datosNoFarmacologico[i][
                    CapaLogica.NO_FARMACOLOGICO_HORA] =
                    ((DatosNoFarmacologico)
                    componentesNoFarmacologico[i]).
                    getHoraNoFarmacologico();

            //Fecha
            datosNoFarmacologico[i][
                    CapaLogica.NO_FARMACOLOGICO_FECHA] =
                    ((DatosNoFarmacologico)
                    componentesNoFarmacologico[i]).
                    getFechaNoFarmacologico();

            //Descripcion
            datosNoFarmacologico[i][
                    CapaLogica.NO_FARMACOLOGICO_DESCRIPCION] =
                    ((DatosNoFarmacologico)
                    componentesNoFarmacologico[i]).
                    getDescripcionNoFarmacologico();

            //Estado
            datosNoFarmacologico[i][CapaLogica.NO_FARMACOLOGICO_ESTADO] = "Activo";
        }
    }
    
    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_botonCancelarActionPerformed

    private void botonAgregarPanelFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarPanelFarmacologicoActionPerformed
        agregarPanel(panelFarmacologicoInterno, new DatosFarmacologico(
                TratamientoMedicamentosoPresentacion.class.getName(), null, this));
    }//GEN-LAST:event_botonAgregarPanelFarmacologicoActionPerformed

    private void botonAgregarPanelNoFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarPanelNoFarmacologicoActionPerformed
        agregarPanel(panelNoFarmacologicoInterno, new DatosNoFarmacologico(this));
    }//GEN-LAST:event_botonAgregarPanelNoFarmacologicoActionPerformed

    private void filtrarFarmacologicoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtrarFarmacologicoKeyReleased
        TableRowSorter<MiModeloTabla> sorter = new TableRowSorter<MiModeloTabla>(
                (MiModeloTabla) tablaFarmacologico.getModel());

        tablaFarmacologico.setRowSorter(sorter);
        String texto = filtrarFarmacologico.getText();
        if (texto.length() == 0) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i).*" + texto + ".*"));
        }
}//GEN-LAST:event_filtrarFarmacologicoKeyReleased

    private void filtrarFarmacologicoActivoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtrarFarmacologicoActivoKeyReleased
        TableRowSorter<MiModeloTabla> sorter = new TableRowSorter<MiModeloTabla>(
                (MiModeloTabla) tablaFarmacologicoActivo.getModel());

        tablaFarmacologicoActivo.setRowSorter(sorter);
        String texto = filtrarFarmacologicoActivo.getText();
        if (texto.length() == 0) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i).*" + texto + ".*"));
        }
    }//GEN-LAST:event_filtrarFarmacologicoActivoKeyReleased

    private void filtrarNoFarmacologicoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtrarNoFarmacologicoKeyReleased
        TableRowSorter<MiModeloTabla> sorter = new TableRowSorter<MiModeloTabla>(
                (MiModeloTabla) tablaNoFarmacologico.getModel());

        tablaNoFarmacologico.setRowSorter(sorter);
        String texto = filtrarNoFarmacologico.getText();
        if (texto.length() == 0) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i).*" + texto + ".*"));
        }
    }//GEN-LAST:event_filtrarNoFarmacologicoKeyReleased

    private void tablaFarmacologicoActivoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaFarmacologicoActivoMouseClicked
        if (evt.getClickCount() == 2 && evt.getButton() == 1) {
            Farmacologico farmacologico = (Farmacologico)
                    MiModeloTabla.recuperarObjetoDeTabla(
                    Farmacologico.class.getName(), tablaFarmacologicoActivo);
            ComunFarmacologicoPresentacion comunFarmacologico =
                    new ComunFarmacologicoPresentacion(this, farmacologico,
                    tablaFarmacologico, tablaFarmacologicoActivo,
                    filtrarFarmacologico, filtrarFarmacologicoActivo,
                    vectorFarmacologicoTratamientoMedicamentoso,
                    vectorFarmacologicoActivo);
            comunFarmacologico.verDetalleFarmacologico();
        } else {
            //Despliega pop-up
            PopUpMenu.crearPopupMenuFarmacologico(tablaFarmacologicoActivo,
                    this, tablaFarmacologico, tablaFarmacologicoActivo,
                    filtrarFarmacologico, filtrarFarmacologicoActivo,
                    vectorFarmacologicoTratamientoMedicamentoso,
                    vectorFarmacologicoActivo);
        }
    }//GEN-LAST:event_tablaFarmacologicoActivoMouseClicked

    private void tablaFarmacologicoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaFarmacologicoMouseClicked
        if (evt.getClickCount() == 2 && evt.getButton() == 1) {
            Farmacologico farmacologico = (Farmacologico)
                    MiModeloTabla.recuperarObjetoDeTabla(
                    Farmacologico.class.getName(), tablaFarmacologico);
            ComunFarmacologicoPresentacion comunFarmacologico =
                    new ComunFarmacologicoPresentacion(this, farmacologico, 
                    tablaFarmacologico, tablaFarmacologicoActivo,
                    filtrarFarmacologico, filtrarFarmacologicoActivo,
                    vectorFarmacologicoTratamientoMedicamentoso,
                    vectorFarmacologicoActivo);
            comunFarmacologico.verDetalleFarmacologico();
        } else {
            //Despliega pop-up
            PopUpMenu.crearPopupMenuFarmacologico(tablaFarmacologico,
                    this, tablaFarmacologico, tablaFarmacologicoActivo,
                    filtrarFarmacologico, filtrarFarmacologicoActivo,
                    vectorFarmacologicoTratamientoMedicamentoso,
                    vectorFarmacologicoActivo);
        }
    }//GEN-LAST:event_tablaFarmacologicoMouseClicked

    private void tablaNoFarmacologicoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaNoFarmacologicoMouseClicked
        if (evt.getClickCount() == 2 && evt.getButton() == 1) {
            NoFarmacologico noFarmacologico = (NoFarmacologico)
                    MiModeloTabla.recuperarObjetoDeTabla(
                    NoFarmacologico.class.getName(),
                    tablaNoFarmacologico);
            
            ComunNoFarmacologicoPresentacion comunNoFarmacologico =
                    new ComunNoFarmacologicoPresentacion(this, noFarmacologico,
                    tablaNoFarmacologico, filtrarNoFarmacologico,
                    vectorNoFarmacologicoTratamientoMedicamentoso);
            comunNoFarmacologico.verDetalleNoFarmacologico();
        } else {
            //Despliega pop-up
            PopUpMenu.crearPopupMenuNoFarmacologico(tablaNoFarmacologico,
                    this, filtrarNoFarmacologico,
                    vectorNoFarmacologicoTratamientoMedicamentoso);
        }
    }//GEN-LAST:event_tablaNoFarmacologicoMouseClicked

    /**
     * Agrega un panel a un panel.
     *
     * @param panelContenedor El panel que contiene al panel que se agregará
     * @param panelComponente El panel componente que se agregará
     */
    private void agregarPanel(JPanel panelContenedor, JPanel panelComponente) {
        panelContenedor.add(panelComponente);
        panelContenedor.revalidate();
        panelContenedor.repaint();
    }

    /**
     * Setea en cada componente del JDialog los eventos que capturarán la tecla
     * enter y escape.
     */
    private void setearEventosQueCapturanTeclaEnterYEscape() {
        //Declaración del evento a capturar
        KeyListener keyListenerEnter = new KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    //Llamada al método que capturará el boton enter y
                    //trabajará sobre el mismo
                    agregarOModificarTratamientoMedicamentoso();
                }
            }
        };
        //Declaración del evento a capturar
        KeyListener keyListenerEscape = new KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    //Llamada al método que capturará el boton enter y
                    //trabajará sobre el mismo
                    dispose();
                }
            }
        };
        //Setear eventos
        tablaFarmacologico.addKeyListener(keyListenerEnter);
        tablaFarmacologico.addKeyListener(keyListenerEscape);
        tablaFarmacologicoActivo.addKeyListener(keyListenerEnter);
        tablaFarmacologicoActivo.addKeyListener(keyListenerEscape);
        tablaNoFarmacologico.addKeyListener(keyListenerEnter);
        tablaNoFarmacologico.addKeyListener(keyListenerEscape);

        filtrarFarmacologicoActivo.addKeyListener(keyListenerEscape);
        filtrarFarmacologico.addKeyListener(keyListenerEscape);
        filtrarNoFarmacologico.addKeyListener(keyListenerEscape);

        botonAceptar.addKeyListener(keyListenerEscape);
        botonAgregarPanelFarmacologico.addKeyListener(keyListenerEscape);
        botonAgregarPanelNoFarmacologico.addKeyListener(keyListenerEscape);
        botonCancelar.addKeyListener(keyListenerEscape);

        solapasTratamientoMedicamentoso.addKeyListener(keyListenerEscape);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonAgregarPanelFarmacologico;
    private javax.swing.JButton botonAgregarPanelNoFarmacologico;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JTextField filtrarFarmacologico;
    private javax.swing.JTextField filtrarFarmacologicoActivo;
    private javax.swing.JTextField filtrarNoFarmacologico;
    private javax.swing.JPanel panelFarmacologico;
    private javax.swing.JPanel panelFarmacologicoInterno;
    private javax.swing.JScrollPane panelFarmacologicoInternoScrollPanel;
    private javax.swing.JPanel panelNoFarmacologico;
    private javax.swing.JPanel panelNoFarmacologicoInterno;
    private javax.swing.JScrollPane panelNoFarmacologicoInternoScrollPanel;
    private javax.swing.JTabbedPane solapasTratamientoMedicamentoso;
    private javax.swing.JTable tablaFarmacologico;
    private javax.swing.JTable tablaFarmacologicoActivo;
    private javax.swing.JScrollPane tablaFarmacologicoActivoScrollPanel;
    private javax.swing.JScrollPane tablaFarmacologicoScrollPanel;
    private javax.swing.JTable tablaNoFarmacologico;
    private javax.swing.JScrollPane tablaNoFarmacologicoScrollPanel;
    private javax.swing.JLabel textoDescriptivoFarmacologico;
    private javax.swing.JLabel textoDescriptivoNoFarmacologico;
    private javax.swing.JLabel textoDescriptivoVentana;
    private javax.swing.JLabel textoEstadoEntidad;
    private javax.swing.JLabel textoFarmacologicoActivo;
    private javax.swing.JLabel textoFiltrarFarmacologico;
    private javax.swing.JLabel textoFiltrarFarmacologicoActivo;
    private javax.swing.JLabel textoFiltrarNoFarmacologico;
    private javax.swing.JLabel textoPanelFarmacologico;
    private javax.swing.JLabel textoPanelNoFarmacologico;
    // End of variables declaration//GEN-END:variables
    private Evolucion evolucion;
    private TratamientoMedicamentoso tratamientoMedicamentoso;
    private Object[][] datosFarmacologico;
    private Object[][] datosNoFarmacologico;
    private Vector<Farmacologico> vectorFarmacologicoTratamientoMedicamentoso;
    private Vector<Farmacologico> vectorFarmacologicoActivo;
    private Vector<NoFarmacologico> vectorNoFarmacologicoTratamientoMedicamentoso;
}